<template>
  <div class="add-article">
    <h2>添加文章</h2>
    <!-- 使用 ArticleEditor 组件 -->
    <ArticleEditor style="height: 100%;" @submit-article="handleArticleSubmit" />
  </div>
</template>

<script setup>
import { ref } from 'vue';
// 导入 ArticleEditor 组件
import ArticleEditor from './ArticleEditor.vue';
import require from '../require';
import Library from './Library.vue';

import { useRouter } from 'vue-router';
const router = useRouter();
const libraryId = ref(router.currentRoute.value.query.libraryId);

// 处理文章提交的方法
const handleArticleSubmit = async (articleData) => {
  const dto = {
    libraryId: libraryId.value,
    title: articleData.title,
    content: articleData.content,
  }
  const res = await require.post('/user/addArticle', dto);
  if (res === 200 || (typeof res !== 'number')) {
    ElMessage.success('文章发布成功');
    console.log('接收到的文章数据:', articleData);
    window.history.back();
  }
};
</script>

<style scoped>
.add-article {
  padding: 20px;
  height: 100vh;
}
</style>
